package com.xiaoze.steampy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoze.steampy.common.lang.Result;
import com.xiaoze.steampy.entity.Game;
import com.xiaoze.steampy.entity.Rechargerecord;
import com.xiaoze.steampy.entity.User;
import com.xiaoze.steampy.service.RechargerecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小泽
 * @since 2022-04-11
 */
@RestController
@RequestMapping("/rechargerecord")
public class RechargerecordController {

    @Autowired
    RechargerecordService rechargerecordService;

    /*
     * 根据用户id拿到全部订单信息
     * */

    @RequestMapping("/getall")
    public Result getAll(@RequestParam("id") Integer id){
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId",id);
        List<Rechargerecord> list = rechargerecordService.listByMap(map);
        // list.forEach(System.out::println);
        return Result.succ(list);
    }

    /*
    * 获取全部订单信息
    *
    * */

    @RequestMapping("/getallorder")
    public Result getAllorder(){
        List<Rechargerecord> list = rechargerecordService.list();
        HashMap<String, List<Rechargerecord>> map = new HashMap<>();
        map.put("order",list);
        return Result.succ(map);
    }

    /*
     * 根据分页获取所有用户
     * */

    @RequestMapping("/allorder")
    public Result getall(Integer currentPage){
        if(currentPage == null || currentPage < 1) {
            currentPage = 1;
        }
        Page<Rechargerecord> page = new Page<>(currentPage,5);
        IPage<Rechargerecord> page1 = rechargerecordService.page(page, new QueryWrapper<Rechargerecord>());
        return Result.succ(page1);
    }
    /*
     * 搜索
     * */

    @GetMapping("/search")
    public Result search(Integer currentPage,String search){
        System.out.println(search);
        if(currentPage == null || currentPage < 1) {
            currentPage = 1;
        }
        Page<Rechargerecord> page = new Page<>(currentPage,5);
        IPage<Rechargerecord> page1 = rechargerecordService.page(page, new QueryWrapper<Rechargerecord>().like("userId","%"+search+"%"));
        return  Result.succ(page1);
    }
}
